{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "803f38db",
   "metadata": {},
   "outputs": [],
   "source": [
    "#函数与模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "6c38493d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user():\n",
    "    \"\"\"问候语函数\"\"\"\n",
    "    print(\"hello world！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "df6b8cc6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world！\n"
     ]
    }
   ],
   "source": [
    "greet_user()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "37ba1a7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user(username):\n",
    "    \"\"\"问候语函数\"\"\"\n",
    "    print(\"hello\",username)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0e3de1f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello CXK\n"
     ]
    }
   ],
   "source": [
    "greet_user(\"CXK\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "2da53c12",
   "metadata": {},
   "outputs": [],
   "source": [
    "import nfu_crawl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "8466fb93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function NFU_NEWS_URL in module nfu_crawl:\n",
      "\n",
      "NFU_NEWS_URL(分类, 页码)\n",
      "    可以快速查询广州南方学院新闻的页面链接\n",
      "    分类:[xxyw\",\"xydt\",\"tzgg\",\"ztb',\"gxdt\"]\n",
      "    页码:[113,106,37,27,29]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(nfu_crawl.NFU_NEWS_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "c516f118",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.enu.cn/xydt/index0.htm\n",
      "https://www.nfu.enu.cn/xydt/index1.htm\n",
      "https://www.nfu.enu.cn/xydt/index2.htm\n",
      "https://www.nfu.enu.cn/xydt/index3.htm\n",
      "https://www.nfu.enu.cn/xydt/index4.htm\n",
      "https://www.nfu.enu.cn/xydt/index5.htm\n",
      "https://www.nfu.enu.cn/xydt/index6.htm\n",
      "https://www.nfu.enu.cn/xydt/index7.htm\n",
      "https://www.nfu.enu.cn/xydt/index8.htm\n",
      "https://www.nfu.enu.cn/xydt/index9.htm\n",
      "https://www.nfu.enu.cn/xydt/index10.htm\n",
      "https://www.nfu.enu.cn/xydt/index11.htm\n",
      "https://www.nfu.enu.cn/xydt/index12.htm\n",
      "https://www.nfu.enu.cn/xydt/index13.htm\n",
      "https://www.nfu.enu.cn/xydt/index14.htm\n",
      "https://www.nfu.enu.cn/xydt/index15.htm\n",
      "https://www.nfu.enu.cn/xydt/index16.htm\n",
      "https://www.nfu.enu.cn/xydt/index17.htm\n",
      "https://www.nfu.enu.cn/xydt/index18.htm\n",
      "https://www.nfu.enu.cn/xydt/index19.htm\n",
      "https://www.nfu.enu.cn/xydt/index20.htm\n",
      "https://www.nfu.enu.cn/xydt/index21.htm\n",
      "https://www.nfu.enu.cn/xydt/index22.htm\n",
      "https://www.nfu.enu.cn/xydt/index23.htm\n",
      "https://www.nfu.enu.cn/xydt/index24.htm\n",
      "https://www.nfu.enu.cn/xydt/index25.htm\n",
      "https://www.nfu.enu.cn/xydt/index26.htm\n",
      "https://www.nfu.enu.cn/xydt/index27.htm\n",
      "https://www.nfu.enu.cn/xydt/index28.htm\n",
      "https://www.nfu.enu.cn/xydt/index29.htm\n",
      "https://www.nfu.enu.cn/xydt/index30.htm\n",
      "https://www.nfu.enu.cn/xydt/index31.htm\n",
      "https://www.nfu.enu.cn/xydt/index32.htm\n",
      "https://www.nfu.enu.cn/xydt/index33.htm\n",
      "https://www.nfu.enu.cn/xydt/index34.htm\n",
      "https://www.nfu.enu.cn/xydt/index35.htm\n",
      "https://www.nfu.enu.cn/xydt/index36.htm\n",
      "https://www.nfu.enu.cn/xydt/index37.htm\n",
      "https://www.nfu.enu.cn/xydt/index38.htm\n",
      "https://www.nfu.enu.cn/xydt/index39.htm\n",
      "https://www.nfu.enu.cn/xydt/index40.htm\n",
      "https://www.nfu.enu.cn/xydt/index41.htm\n",
      "https://www.nfu.enu.cn/xydt/index42.htm\n",
      "https://www.nfu.enu.cn/xydt/index43.htm\n",
      "https://www.nfu.enu.cn/xydt/index44.htm\n",
      "https://www.nfu.enu.cn/xydt/index45.htm\n",
      "https://www.nfu.enu.cn/xydt/index46.htm\n",
      "https://www.nfu.enu.cn/xydt/index47.htm\n",
      "https://www.nfu.enu.cn/xydt/index48.htm\n",
      "https://www.nfu.enu.cn/xydt/index49.htm\n",
      "https://www.nfu.enu.cn/xydt/index50.htm\n",
      "https://www.nfu.enu.cn/xydt/index51.htm\n",
      "https://www.nfu.enu.cn/xydt/index52.htm\n",
      "https://www.nfu.enu.cn/xydt/index53.htm\n",
      "https://www.nfu.enu.cn/xydt/index54.htm\n",
      "https://www.nfu.enu.cn/xydt/index55.htm\n",
      "https://www.nfu.enu.cn/xydt/index56.htm\n",
      "https://www.nfu.enu.cn/xydt/index57.htm\n",
      "https://www.nfu.enu.cn/xydt/index58.htm\n",
      "https://www.nfu.enu.cn/xydt/index59.htm\n",
      "https://www.nfu.enu.cn/xydt/index60.htm\n",
      "https://www.nfu.enu.cn/xydt/index61.htm\n",
      "https://www.nfu.enu.cn/xydt/index62.htm\n",
      "https://www.nfu.enu.cn/xydt/index63.htm\n",
      "https://www.nfu.enu.cn/xydt/index64.htm\n",
      "https://www.nfu.enu.cn/xydt/index65.htm\n",
      "https://www.nfu.enu.cn/xydt/index66.htm\n",
      "https://www.nfu.enu.cn/xydt/index67.htm\n",
      "https://www.nfu.enu.cn/xydt/index68.htm\n",
      "https://www.nfu.enu.cn/xydt/index69.htm\n",
      "https://www.nfu.enu.cn/xydt/index70.htm\n",
      "https://www.nfu.enu.cn/xydt/index71.htm\n",
      "https://www.nfu.enu.cn/xydt/index72.htm\n",
      "https://www.nfu.enu.cn/xydt/index73.htm\n",
      "https://www.nfu.enu.cn/xydt/index74.htm\n",
      "https://www.nfu.enu.cn/xydt/index75.htm\n",
      "https://www.nfu.enu.cn/xydt/index76.htm\n",
      "https://www.nfu.enu.cn/xydt/index77.htm\n",
      "https://www.nfu.enu.cn/xydt/index78.htm\n",
      "https://www.nfu.enu.cn/xydt/index79.htm\n",
      "https://www.nfu.enu.cn/xydt/index80.htm\n",
      "https://www.nfu.enu.cn/xydt/index81.htm\n",
      "https://www.nfu.enu.cn/xydt/index82.htm\n",
      "https://www.nfu.enu.cn/xydt/index83.htm\n",
      "https://www.nfu.enu.cn/xydt/index84.htm\n",
      "https://www.nfu.enu.cn/xydt/index85.htm\n",
      "https://www.nfu.enu.cn/xydt/index86.htm\n",
      "https://www.nfu.enu.cn/xydt/index87.htm\n",
      "https://www.nfu.enu.cn/xydt/index88.htm\n",
      "https://www.nfu.enu.cn/xydt/index89.htm\n",
      "https://www.nfu.enu.cn/xydt/index90.htm\n",
      "https://www.nfu.enu.cn/xydt/index91.htm\n",
      "https://www.nfu.enu.cn/xydt/index92.htm\n",
      "https://www.nfu.enu.cn/xydt/index93.htm\n",
      "https://www.nfu.enu.cn/xydt/index94.htm\n",
      "https://www.nfu.enu.cn/xydt/index95.htm\n",
      "https://www.nfu.enu.cn/xydt/index96.htm\n",
      "https://www.nfu.enu.cn/xydt/index97.htm\n",
      "https://www.nfu.enu.cn/xydt/index98.htm\n",
      "https://www.nfu.enu.cn/xydt/index99.htm\n",
      "https://www.nfu.enu.cn/xydt/index100.htm\n",
      "https://www.nfu.enu.cn/xydt/index101.htm\n",
      "https://www.nfu.enu.cn/xydt/index102.htm\n",
      "https://www.nfu.enu.cn/xydt/index103.htm\n",
      "https://www.nfu.enu.cn/xydt/index104.htm\n",
      "https://www.nfu.enu.cn/xydt/index105.htm\n"
     ]
    }
   ],
   "source": [
    "NFU_NEWS_URL(\"xydt\",106)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "a9f0dfdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "def describe_pet(animal_type,pet_name):\n",
    "    \"\"\"显示宠物信息\"\"\"\n",
    "    print(\"\\nI have a\" + animal_type + \".\")\n",
    "    print(\"My\" + animal_type + \"'s name is \"+pet_name.title() + \".\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "41dc5133",
   "metadata": {},
   "outputs": [],
   "source": [
    "#*positional argument(位置参数)\n",
    "#*keyword argument(关键字参数)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "298e7af0",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (<ipython-input-48-abf9612f1711>, line 6)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-48-abf9612f1711>\"\u001b[1;36m, line \u001b[1;32m6\u001b[0m\n\u001b[1;33m    func_test(x=1,2)\u001b[0m\n\u001b[1;37m                  ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "#eg1\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(x=1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "135bbb16",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "#eg2\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(1,y=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "9b6d5c68",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (<ipython-input-50-6f08ead4c4e4>, line 6)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-50-6f08ead4c4e4>\"\u001b[1;36m, line \u001b[1;32m6\u001b[0m\n\u001b[1;33m    func_test(1,y=2,3)\u001b[0m\n\u001b[1;37m                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "#eg3\n",
    "def func_test(x,y,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(1,y=2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "69550ba7",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "func_test() got multiple values for argument 'y'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-51-29744f463fdd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mfunc_test\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: func_test() got multiple values for argument 'y'"
     ]
    }
   ],
   "source": [
    "#eg4\n",
    "def func_test(x,y,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(1,3,y=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "df0e28cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n",
      "hello world\n"
     ]
    }
   ],
   "source": [
    "print(\"hello world\")\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "a2e694ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function print in module builtins:\n",
      "\n",
      "print(...)\n",
      "    print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n",
      "    \n",
      "    Prints the values to a stream, or to sys.stdout by default.\n",
      "    Optional keyword arguments:\n",
      "    file:  a file-like object (stream); defaults to the current sys.stdout.\n",
      "    sep:   string inserted between values, default a space.\n",
      "    end:   string appended after the last value, default a newline.\n",
      "    flush: whether to forcibly flush the stream.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(print)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7bdc38f",
   "metadata": {},
   "outputs": [],
   "source": [
    "*对于计算机而言：函数必须有返回值 return （公里）\n",
    "*python：返回值给了一个默认值（none），也应该写一个返回值\n",
    "1.返回函数过程的计算结果\n",
    "2.返回函数过程运算的过程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "ee751a3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    \"\"\"计算y=2x\"\"\"\n",
    "    y = 2*x\n",
    "    return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "1989bec6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "print(func(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08f31818",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
